<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<div class="well widget">
				<div class="widget-header">
					<a href="{$ADMIN_SCRIPT}/admin/menu">{lang admin.menu.view.header}</a>
		            <!--{loop $crumbs $crumb}-->
		            / <a href="{$ADMIN_SCRIPT}/admin/menu&parentid={$crumb[MENUID]}">{$crumb[CNAME]}</a>
		            <!--{/loop}-->
				</div>
				<div class="widget-content">
					<div class="action-wrapper">
						<div class="pull-left">
							<a href="javascript:void(null);" id="btn_submit" class="btn btn-small btn-primary" {$dispatches[operations][edit]}>{lang admin.operation.submit}</a>
							<a href="javascript:void(null);" id="btn_delete_list" class="btn btn-small" {$dispatches[operations][delete]}>{lang admin.operation.delete}</a>
							<!--{if $_var['current']['USERID'] == -1 && $_var[gp_parentid] > 0}-->
							<a href="javascript:void(null);" id="btn_move_list" class="btn btn-small" {$dispatches[operations][move]}>{lang admin.operation.move}</a>
							<!--{/if}-->
							<a href="{$ADMIN_SCRIPT}/admin/menu/_add&parentid={$_var[gp_parentid]}" {$dispatches[operations][add]} class="btn btn-small">{lang admin.menu.view.operation.add}</a>
						</div>
					</div>
					
					<hr/>
					<form id="frm_grid" name="frmGrid" action="{$ADMIN_SCRIPT}/admin/menu&parentid={$_var[gp_parentid]}" method="post">
					<input type="hidden" name="hdnMoveMenuID" id="hdn_move_menuid" value="" />
					<table class="table table-hover">
						<thead>
							<tr>
								<th width="20"><input type="checkbox" class="fancy" name="cbxAll"/></th>
								<th width="55">{lang admin.menu.view.th.no}</th>
					            <th>{lang admin.menu.view.th.name}</th>
					            <th>{lang admin.menu.view.th.link}</th>
					            <th width="60">{lang admin.menu.view.th.type}</th>
					            <th width="120">{lang admin.menu.view.th.edit}</th>
					            <th width="60">{lang admin.menu.view.th.child}</th>
					            <th width="85">{lang admin.menu.view.th.operate}</th>
							</tr>
						</thead>
						<tbody>
							<!--{loop $menus $_loop $menu}-->
							<tr class="item-row">
							<td>
								<!--{if $menu['CHILDREN'] == 0}-->
				                <input type="checkbox" class="fancy" name="cbxItem[]" cname="{$menu[CNAME]}" value="{$menu[MENUID]}"/>
				                <!--{/if}-->
				            </td>
				            <td>
				             	<input type="text" class="input-mini" size="4" name="displayorder[{$menu[MENUID]}]" value="{$menu[DISPLAYORDER]}" />
				            </td>
				            <td>
				            	<i class="micon {$menu[ICON]}"></i>
				            	<!--{if $menu['PARENTID']}-->{$menu[CNAME]}<!--{else}--><a href="{$ADMIN_SCRIPT}/admin/menu&parentid={$menu[MENUID]}">{$menu[CNAME]}</a><!--{/if}-->
				            </td>
				            <td>
				            	{$menu[URL]}
				            </td>
				            <td class="f10">
				            	{$menu[TYPE]}
				            </td>
				            <td class="f10">
				            	{$menu[EDITER]}<br/>
				            	{echo $menu['EDITTIME']? date('Y-m-d H:i', strtotime($menu[EDITTIME])) : '';}
				            </td>
				            <td>
				                <!--{if $menu['PARENTID']}-->—<!--{else}--><a href="{$ADMIN_SCRIPT}/admin/menu&parentid={$menu[MENUID]}">{$menu[CHILDREN]}</a><!--{/if}-->
				            </td>
				            <td>
				            	<!--{if $_var['current']['USERID'] == -1 || ($menu['MENUID'] != 1 && $menu['PARENTID'] != 1)}-->
				            	<a class="btn btn-mini btn-primary" href="{$ADMIN_SCRIPT}/admin/menu/_update&id={$menu[MENUID]}&parentid={$_var[gp_parentid]}" {$dispatches[operations][edit]}>{lang admin.operation.edit}</a>
				                <!--{/if}-->
				                <!--{if $menu['CHILDREN'] == 0}-->
				                <a class="btn btn-mini btn-delete" cname="{$menu[CNAME]}" data="{$menu[MENUID]}" href="javascript:void(null);" {$dispatches[operations][delete]}>{lang admin.operation.delete}</a>
				                <!--{/if}-->
				            </td>
				            </tr>
				            <!--{/loop}-->
				            
				            <!--{if $count == 0}-->
					        <tr>
					            <td colspan="8">
					                * {lang admin.operation.empty}
					            </td>
					        </tr>
					        <!--{/if}-->
						</tbody>
					</table>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
$(function(){
	$('.fancy').uniform();
	
	$('#btn_submit').click(function(){
		$('#frm_grid').submit();
	});
	
	$('#btn_delete_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			var tempHTML = '<p>';
			$("#frm_grid input[name='cbxItem[]']:checked").each(function(){
				tempHTML += $(this).attr('cname') + '； ';
			});
			
			tempHTML += '</p>';
			
			$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang admin.menu.view.operation.delete.message}</p>' + tempHTML, callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/admin/menu&do=delete_list&parentid={$_var[gp_parentid]}');
					$('#frm_grid').submit();
				});
			}});
		}else $.dialog({ message:'{lang admin.menu.view.operation.empty}'});
	});
	
	$('#btn_move_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			$.dialog({submit:'{lang admin.operation.move}', title:'{lang admin.menu.view.operation.move.message}', href:'{$ADMIN_SCRIPT}/admin/menu/_move', callback: function(){
            	$('#slt_move_menuid').change(function(){
            		var childmenus = $('#slt_child_move_menuid').get(0);
            		childmenus.options.length = 1;
            		$('#slt_child_move_menuid').hide();
            		$('#modal_dialog .help-inline').html('');
            		$('#hdn_dialog_move_menuid').val($(this).val());
            		
            		$.getJSON('{$ADMIN_SCRIPT}/admin/menu/_children', {parentid:$(this).val()}, function(data){
            			if(data.length > 0){
            				$(childmenus).show();
            				
            				for(var i = 0; i < data.length; i++){
            					childmenus.options[i + 1] = new Option(data[i].CNAME, data[i].MENUID);
            				}
            			}
            		});
            	});
            	
            	$('#slt_child_move_menuid').change(function(){
            		$('#modal_dialog .help-inline').html('');
            		$('#hdn_dialog_move_menuid').val($(this).val());
            	});
            	
				$('#modal_dialog .btn-primary').click(function(){
            		$('#hdn_move_menuid').val($('#hdn_dialog_move_menuid').val());
            		
			        if($('#hdn_move_menuid').val().trim().length == 0){
			        	$('#modal_dialog .help-inline').html('{lang admin.menu.view.operation.move.empty}');
			        	return false;
			        }
			        
			        $('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/admin/menu/_move&formsubmit=yes&parentid={$_var[gp_parentid]}');
			        $('#frm_grid').submit();
            	});
            }});
		}else $.dialog({message:'{lang admin.menu.view.operation.empty}'});
	});
	
	$("#frm_grid input[name='cbxAll']").click(function(){
		if(this.checked){
			$('#frm_grid .item-row').addClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', true).parent().addClass('checked');
		}else{
			$('#frm_grid .item-row').removeClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', false).parent().removeAttr('class');
		}
	});
	
	$("#frm_grid input[name='cbxItem[]']").click(function(){
		if(this.checked) $(this).parent().parent().parent().parent().addClass('warning');
		else $(this).parent().parent().parent().parent().removeClass('warning');
	});
	
	$('#frm_grid .btn-delete').click(function(){
		var menuid = $(this).attr('data');
		var tempHTML = '<p>' + $(this).attr('cname') + '； </p>';
		$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang admin.menu.view.operation.delete.one}</p>' + tempHTML, callback:function(){
			$('#modal_dialog .btn-primary').click(function(){
				$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/admin/menu&do=delete&id=' + menuid + '&parentid={$_var[gp_parentid]}');
				$('#frm_grid').submit();
			});
		}});
	});
});
</script>

<!--{template /module/admin/view/foot}-->